package com.example.Less.repository;

import com.example.Less.entity.Photo;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.HashMap;
import java.util.List;
import java.util.Objects;

@Repository
public interface PhotoRepository extends JpaRepository<Photo, Integer> {



    @Query("SELECT p FROM Photo p WHERE " +
            "(:photoName IS NULL OR p.photoName LIKE %:photoName%) AND " +
            "(:photoPath IS NULL OR p.photoPath LIKE %:photoPath%) AND " +
            "(:type IS NULL OR p.type = :type) AND " +
            "(:projectId IS NULL OR p.projectId = :projectId) AND " +
            "(:isDeleted IS NULL OR p.isDeleted = :isDeleted)")
    Page<Photo> searchPhotos(@Param("photoName") String photoName,
                             @Param("photoPath") String photoPath,
                             @Param("type") String type,
                             @Param("projectId") Integer projectId,
                             @Param("isDeleted") Integer isDeleted,
                             Pageable pageable);
}